package br.com.foxinline.utilitario;

import java.text.ParseException;
import javax.swing.text.MaskFormatter;

/**
 *
 * @author elyjr
 */
public class Caracteres {

    public static String cpfMask = "###.###.###-##";
    public static String cnpjMask = "##.###.###/####-##";
    public static String cepMask = "##.###-###";
    public static String phoneMask = "(##) ####-####";

    public static String removecaracter(String s) {
        if (s != null) {
            s = s.replace(".", "").replace("-", "").replace("/", "").replace("-", "").replaceAll("\\.", "").replace("-", "").replace("/", "").replace("-", "").replace("[", "").replace("]", "").replace("{", "").replace("}", "").replace("(", "").replace(")", "");
        }
        return s;
    }

    public static String adicionarMascara(String string, String mask) {
        MaskFormatter maskFormatter;

        try {
            if (string != null && !string.isEmpty()) {
                maskFormatter = new MaskFormatter(mask);
                maskFormatter.setValueContainsLiteralCharacters(false);
                return maskFormatter.valueToString(string);
            } else {
                return "";
            }
        } catch (ParseException ex) {
            throw new RuntimeException(ex);
        }
    }

    /**
     * Remove caracteres especiais e substitui letras acentuadas
     * @param text
     * @return 
     */
    public static String removeCaracteresEspeciais(String text) {
        if (text == null) {
            return "";
        }
        return text.replaceAll("-", "").replaceAll("[ãâàáä]", "a").replaceAll("[êèéë]", "e").replaceAll("[îìíï]", "i").replaceAll("[õôòóö]", "o").replaceAll("[ûúùü]", "u").replaceAll("[ÃÂÀÁÄ]", "A").replaceAll("[ÊÈÉË]", "E").replaceAll("[ÎÌÍÏ]", "I").replaceAll("[ÕÔÒÓÖ]", "O").replaceAll("[ÛÙÚÜ]", "U").replace('ç', 'c').replace('Ç', 'C').replace('ñ', 'n').replace('Ñ', 'N').replaceAll("!", "").replaceAll("\\[\\´\\`\\?!\\@\\#\\$\\%\\¨\\*", " ").replaceAll("\\(\\)\\=\\{\\}\\[\\]\\~\\^\\]", " ").replaceAll("[\\.\\;\\-\\_\\+\\'\\ª\\º\\:\\;\\/]", " ");
    }
}
